package com.example.gw_back_end.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.gw_back_end.domain.entities.PostView;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface PostViewMapper extends BaseMapper<PostView> {
    @Update("UPDATE tb_post_view SET view_count = view_count + 1 WHERE post_id = #{postId}")
    void updateViewCount(@Param("postId") Integer postId);

    // 查询当前浏览量
    @Select("SELECT view_count FROM tb_post_view WHERE post_id = #{postId}")
    Integer selectViewCount(@Param("postId") Integer postId);
}
